package org.example.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.example.entity.Pubcomment;
import org.example.mapper.PubcommentMapper;
import org.example.service.IPubcommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PubcommentServiceImpl extends ServiceImpl<PubcommentMapper, Pubcomment> implements IPubcommentService {

    @Autowired
    private PubcommentMapper pubcommentMapper;


    @Override
    public Double avgScore(Integer pid) {
        return pubcommentMapper.avgScore(pid);
    }

    @Override
    public Integer[] countScore(Integer pid, Integer[] score) {
        Integer[] scores = new Integer[score.length];
        for (int i = 0; i < score.length; i++) {
            switch (score[i]) {
                case 1 -> scores[i] = pubcommentMapper.countScore(pid, 1);
                case 2 -> scores[i] = pubcommentMapper.countScore(pid, 2);
                case 3 -> scores[i] = pubcommentMapper.countScore(pid, 3);
                case 4 -> scores[i] = pubcommentMapper.countScore(pid, 4);
                case 5 -> scores[i] = pubcommentMapper.countScore(pid, 5);
            }
        }
        return scores;
    }
}
